import { defineStore } from 'pinia';
interface INodes {
  nodeName?: string;
  [name: string]: any;
}

export interface INodeConfig {
  nodeName: string; // 节点名称
  type: number; // 节点类型
  nodeUserList: any[]; // 节点用户列表
  conditionNodes?: INodes[];
  error: boolean;
  childNode: INodeConfig | null;
}

interface IState {
  nodeConfig: any;
  isTried: boolean;
  directorMaxLevel: number;
  errorList: any[];
  title: string;
  flowPermission: any[];
  step: number;
  conditionList: any[];
}

export const useWorkFlow = defineStore('app-work-flow', {
  state: (): IState => {
    return {
      // 默认数据
      nodeConfig: {
        nodeName: '发起人',
        type: 0,
        priorityLevel: '',
        settype: '',
        selectMode: '',
        selectRange: '',
        directorLevel: '',
        examineMode: '',
        noHanderAction: '',
        examineEndDirectorLevel: '',
        ccSelfSelectFlag: '',
        conditionList: [],
        nodeUserList: [],
        childNode: null,
      },
      // 尝试提交数据，即用户意义的完成流程创建
      isTried: false,
      // 主管最多有多少级
      directorMaxLevel: 20,
      // 错误信息
      errorList: [],
      title: '',
      flowPermission: [],
      step: 1,
      conditionList: [],
    };
  },
  actions: {
    delNode(node) {
      this.nodeConfig = node;
    },
    asyncTitle(title) {
      this.title = title;
    },
    asyncFlowPermission(flowPermission) {
      this.flowPermission = flowPermission;
    },
    asyncStep(step) {
      this.step = step;
    },
    asyncConditionList(conditionList) {
      this.conditionList = conditionList;
    },
  },
});
